import { useRef, useEffect, useState } from "react"
import { Input } from "antd"
export default function RefHook() {
    let myInputRef = useRef()
    const [input,setInput] = useState('')
    useEffect(() => {
        if (input === '') {
            // 获取焦点
            myInputRef.current.input.focus()
        }
    },[])
    function onInput() {
        return (e) => {
            setInput(e.target.value || '')
        }
    }
    return (
        <>
            <h2>{ input }</h2>
            <Input ref={myInputRef} value={input} onChange={onInput()}></Input>
        </>
    )
}